package com.hui.servlet.classes;

import com.hui.entity.Class;
import com.hui.service.ClassService;
import com.hui.util.ServiceFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 李昭辉
 * @Date: 2021/07/09/15:43
 * @Description:
 */
@WebServlet(name = "delClassServlet", urlPatterns = "/delClass")
public class DelClassServlet extends HttpServlet {
    private ClassService classService = ServiceFactory.getClassService();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        boolean b = classService.delClass(Integer.parseInt(id));
        PrintWriter writer = resp.getWriter();
        if(b){
            writer.write("<script>window.alert('删除成功!');window.location.href='classes'</script>");
        }else{
            writer.write("<script>window.alert('删除失败!!!');window.location.href='classes'</script>");
        }
        writer.close();
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
